package com.cenntro.common.mq.producer.processor;

import java.io.Serializable;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;

import lombok.Data;
@Data
public class MQSendResult implements Serializable{

	private static final long serialVersionUID = 1L;
	/**
	 * 是否发送成功
	 */
	private boolean isSendSuccess;
	/**
	 * 错误信息
	 */
	private String errMsg;
	/**
	 * 错误堆栈信息
	 */
	private Throwable e;
	/**
	 * 消息ID
	 */
	private String msgId;
	/**
	 * sendResult对象
	 */
	private SendResult sendResult;
	
	public MQSendResult() {
		super();
		this.isSendSuccess = false;
	}

	public MQSendResult(SendResult sendResult) {
		super();
		this.sendResult = sendResult;
		//判断是否发送成功
        if (sendResult == null || sendResult.getSendStatus() != SendStatus.SEND_OK) {
            //失败
        	this.isSendSuccess=false;
        	this.errMsg="发送失败";
        }else{
        	//成功
        	this.isSendSuccess=true;
        	this.msgId = sendResult.getMsgId();
        }
	}
	
	public MQSendResult(String errMsg, Throwable e) {
		super();
		this.errMsg = errMsg;
		this.e = e;
		this.isSendSuccess = false;
	}
	
}
